package com.lcm.fas.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.LineBorder;

import com.lcm.fas.controller.FileController;
import com.lcm.fas.model.FileInfo;

public class FileAnalysInternalFrame extends JInternalFrame implements ActionListener{
	private static final long serialVersionUID = 1L;
	private static JTable table;
	private MyTableModel<FileInfo> tableModel;//自定义的表格模板
	List<List<FileInfo>> files = new ArrayList<List<FileInfo>>();
	private int selectdCount=0;//选中的行数
	private int pageIndex=2;//当前页索引，默认是2（即图片页）
	private static JLabel audioCount;
	private static JLabel videoCount;
	private static JLabel imageCount;
	private static JLabel docCount;
	private static JLabel otherCount;
	private static JPanel panel;
	private static JPanel panel_1;
	private static JPanel panel_1_1;
	private static JPanel panel_1_2;
	private static JPanel panel_1_3;
	private static JPanel panel_1_4;
	private static JLabel lblNewLabel;
	private static JLabel lblNewLabel_2;
	private static JLabel lblNewLabel_3;
	private static JLabel lblNewLabel_4;
	private static JLabel lblNewLabel_5;
	/**
	 * Create the frame
	 */
	public FileAnalysInternalFrame() {
		setTitle("文件管理系统");
		setIconifiable(true);//支持窗口最小化显示
		setClosable(true);//支持窗口可关闭
		//获取屏幕尺寸
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		//设置尺寸大小
		setBounds(0,0,1190,640);
		
		panel = new JPanel();
		panel.setBorder(UIManager.getBorder("Button.border"));
		getContentPane().add(panel, BorderLayout.NORTH);
			
		panel_1 = new JPanel();
		panel_1.setBorder(new LineBorder(Color.LIGHT_GRAY, 3));
		panel_1.setBackground(new Color(255, 204, 153));
//######TODO  0音乐类
		panel_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				pageIndex = 0;//更新选中的页索引
				System.out.println("当前页： "+pageIndex);
				panel_1.setBackground(getBackground());
				initTable(MainFrame.ROOT_PATH, 0);
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				pageIndex = 0;//更新选中的页索引
				panel_1.setBackground(getBackground());
				initTable(MainFrame.ROOT_PATH, 0);
			}
			@Override
			public void mouseExited(MouseEvent e) {
				panel_1.setBackground(new Color(255, 204, 153));
				System.out.println("音频文件3");
			}
		});
		
		panel_1_1 = new JPanel();
		panel_1_1.setBorder(new LineBorder(Color.LIGHT_GRAY, 3));
		panel_1_1.setBackground(new Color(102, 204, 51));
//######TODO  1视频类
		panel_1_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				pageIndex = 1;//更新选中的页索引
				System.out.println("当前页： "+pageIndex);
				panel_1_1.setBackground(getBackground());
				initTable(MainFrame.ROOT_PATH, 1);
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				pageIndex = 1;//更新选中的页索引
				panel_1_1.setBackground(getBackground());
				initTable(MainFrame.ROOT_PATH, 1);
			}
			@Override
			public void mouseExited(MouseEvent e) {
				panel_1_1.setBackground(new Color(102, 204, 51));
			}
		});
		
		videoCount = new JLabel("0");
		videoCount.setHorizontalAlignment(SwingConstants.CENTER);
		
		lblNewLabel_2 = new JLabel("视频");
		lblNewLabel_2.setIcon(new ImageIcon(FileAnalysInternalFrame.class.getResource("/image/音视频80_96xp.png")));
		
		GroupLayout gl_panel_1_1 = new GroupLayout(panel_1_1);
		gl_panel_1_1.setHorizontalGroup(
			gl_panel_1_1.createParallelGroup(Alignment.LEADING)
				.addGap(0, 219, Short.MAX_VALUE)
				.addGroup(gl_panel_1_1.createSequentialGroup()
					.addGroup(gl_panel_1_1.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel_1_1.createSequentialGroup()
							.addGap(47)
							.addComponent(lblNewLabel_2))
						.addGroup(gl_panel_1_1.createSequentialGroup()
							.addGap(26)
							.addComponent(videoCount, GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(26, Short.MAX_VALUE))
		);
		gl_panel_1_1.setVerticalGroup(
			gl_panel_1_1.createParallelGroup(Alignment.LEADING)
				.addGap(0, 90, Short.MAX_VALUE)
				.addGroup(gl_panel_1_1.createSequentialGroup()
					.addComponent(lblNewLabel_2)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(videoCount, GroupLayout.PREFERRED_SIZE, 28, Short.MAX_VALUE))
		);
		panel_1_1.setLayout(gl_panel_1_1);
		
		panel_1_2 = new JPanel();
		panel_1_2.setBorder(new LineBorder(Color.LIGHT_GRAY, 3));
		panel_1_2.setBackground(new Color(204, 204, 102));
		
//######TODO  2图片类
		panel_1_2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				pageIndex = 2;//更新选中的页索引
				System.out.println("当前页： "+pageIndex);
				panel_1_2.setBackground(getBackground());
				initTable(MainFrame.ROOT_PATH, 2);
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				pageIndex = 2;//更新选中的页索引
				panel_1_2.setBackground(getBackground());
				initTable(MainFrame.ROOT_PATH, 2);
			}
			@Override
			public void mouseExited(MouseEvent e) {
				panel_1_2.setBackground(new Color(204, 204, 102));
				System.out.println("图片文件3");
			}
		});
		
		imageCount = new JLabel("0");
		imageCount.setHorizontalAlignment(SwingConstants.CENTER);
		
		lblNewLabel_3 = new JLabel("图片");
		lblNewLabel_3.setIcon(new ImageIcon(FileAnalysInternalFrame.class.getResource("/image/图片.png")));
		GroupLayout gl_panel_1_2 = new GroupLayout(panel_1_2);
		gl_panel_1_2.setHorizontalGroup(
			gl_panel_1_2.createParallelGroup(Alignment.LEADING)
				.addGap(0, 219, Short.MAX_VALUE)
				.addGroup(gl_panel_1_2.createSequentialGroup()
					.addGroup(gl_panel_1_2.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel_1_2.createSequentialGroup()
							.addGap(47)
							.addComponent(lblNewLabel_3))
						.addGroup(gl_panel_1_2.createSequentialGroup()
							.addGap(26)
							.addComponent(imageCount, GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(26, Short.MAX_VALUE))
		);
		gl_panel_1_2.setVerticalGroup(
			gl_panel_1_2.createParallelGroup(Alignment.LEADING)
				.addGap(0, 90, Short.MAX_VALUE)
				.addGroup(gl_panel_1_2.createSequentialGroup()
					.addComponent(lblNewLabel_3)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(imageCount, GroupLayout.PREFERRED_SIZE, 28, Short.MAX_VALUE))
		);
		panel_1_2.setLayout(gl_panel_1_2);
		
		panel_1_3 = new JPanel();
		panel_1_3.setBorder(new LineBorder(Color.LIGHT_GRAY, 3));
		panel_1_3.setBackground(new Color(102, 204, 204));
		
//######TODO  3文档类
		panel_1_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				pageIndex = 3;//更新选中的页索引
				System.out.println("当前页： "+pageIndex);
				panel_1_3.setBackground(getBackground());
				initTable(MainFrame.ROOT_PATH, 3);
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				pageIndex = 3;//更新选中的页索引
				panel_1_3.setBackground(getBackground());
				initTable(MainFrame.ROOT_PATH, 3);
			}
			@Override
			public void mouseExited(MouseEvent e) {
				panel_1_3.setBackground(new Color(102, 204, 204));
				System.out.println("文档文件3");
			}
		});
		docCount = new JLabel("0");
		docCount.setHorizontalAlignment(SwingConstants.CENTER);
		
		lblNewLabel_4 = new JLabel("文档");
		lblNewLabel_4.setIcon(new ImageIcon(FileAnalysInternalFrame.class.getResource("/image/文档.png")));
		GroupLayout gl_panel_1_3 = new GroupLayout(panel_1_3);
		gl_panel_1_3.setHorizontalGroup(
			gl_panel_1_3.createParallelGroup(Alignment.LEADING)
				.addGap(0, 219, Short.MAX_VALUE)
				.addGroup(gl_panel_1_3.createSequentialGroup()
					.addGroup(gl_panel_1_3.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel_1_3.createSequentialGroup()
							.addGap(47)
							.addComponent(lblNewLabel_4))
						.addGroup(gl_panel_1_3.createSequentialGroup()
							.addGap(26)
							.addComponent(docCount, GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(26, Short.MAX_VALUE))
		);
		gl_panel_1_3.setVerticalGroup(
			gl_panel_1_3.createParallelGroup(Alignment.LEADING)
				.addGap(0, 90, Short.MAX_VALUE)
				.addGroup(gl_panel_1_3.createSequentialGroup()
					.addComponent(lblNewLabel_4)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(docCount, GroupLayout.PREFERRED_SIZE, 28, Short.MAX_VALUE))
		);
		panel_1_3.setLayout(gl_panel_1_3);
		
		panel_1_4 = new JPanel();
		panel_1_4.setBorder(new LineBorder(Color.LIGHT_GRAY, 3));
		panel_1_4.setBackground(new Color(204, 204, 255));
		
//######TODO  4其他类
		panel_1_4.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				pageIndex = 4;//更新选中的页索引
				System.out.println("当前页： "+pageIndex);
				panel_1_4.setBackground(getBackground());
				initTable(MainFrame.ROOT_PATH, 4);
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				pageIndex = 4;//更新选中的页索引
				panel_1_4.setBackground(getBackground());
				initTable(MainFrame.ROOT_PATH, 4);
			}
			@Override
			public void mouseExited(MouseEvent e) {
				panel_1_4.setBackground(new Color(204, 204, 255));
				System.out.println("其他资源3");
			}
		});
		otherCount = new JLabel("0");
		otherCount.setHorizontalAlignment(SwingConstants.CENTER);
		
		lblNewLabel_5 = new JLabel("其他资源");
		lblNewLabel_5.setIcon(new ImageIcon(FileAnalysInternalFrame.class.getResource("/image/其他 28.png")));
		GroupLayout gl_panel_1_4 = new GroupLayout(panel_1_4);
		gl_panel_1_4.setHorizontalGroup(
			gl_panel_1_4.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1_4.createSequentialGroup()
					.addGroup(gl_panel_1_4.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel_1_4.createSequentialGroup()
							.addContainerGap()
							.addComponent(lblNewLabel_5, GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE))
						.addGroup(gl_panel_1_4.createSequentialGroup()
							.addGap(26)
							.addComponent(otherCount, GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap())
		);
		gl_panel_1_4.setVerticalGroup(
			gl_panel_1_4.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1_4.createSequentialGroup()
					.addComponent(lblNewLabel_5)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(otherCount, GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE))
		);
		panel_1_4.setLayout(gl_panel_1_4);
		
		lblNewLabel = new JLabel("音频");
		lblNewLabel.setIcon(new ImageIcon(FileAnalysInternalFrame.class.getResource("/image/音乐.png")));
		
		audioCount = new JLabel("0");
		audioCount.setHorizontalAlignment(SwingConstants.CENTER);
		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel_1.createSequentialGroup()
							.addGap(47)
							.addComponent(lblNewLabel))
						.addGroup(gl_panel_1.createSequentialGroup()
							.addGap(26)
							.addComponent(audioCount, GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(26, Short.MAX_VALUE))
		);
		gl_panel_1.setVerticalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addComponent(lblNewLabel)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(audioCount, GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE))
		);
		panel_1.setLayout(gl_panel_1);
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 240, GroupLayout.PREFERRED_SIZE)
					.addGap(5)
					.addComponent(panel_1_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(5)
					.addComponent(panel_1_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(5)
					.addComponent(panel_1_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(5)
					.addComponent(panel_1_4, GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addComponent(panel_1, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
				.addComponent(panel_1_1, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
				.addComponent(panel_1_2, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
				.addComponent(panel_1_3, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
				.addComponent(panel_1_4, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
		);
		panel.setLayout(gl_panel);
		
//##############TODO 右键菜单的定义：PopupMenu对象
//		首先，需要声明一个PopupMenu对像。
		JPopupMenu popupMenu1 = new JPopupMenu();
//		然后新建一些子菜单，这里我们使用建立三个菜单项
		JMenuItem menuItem1 = new JMenuItem("打开");
		JMenuItem menuItem2 = new JMenuItem("删除");
		JMenuItem menuItem3 = new JMenuItem("重命名");
		
		menuItem1.setFont(new Font(MainFrame.fontType, Font.PLAIN, 20));
		menuItem2.setFont(new Font(MainFrame.fontType, Font.PLAIN, 20));
		menuItem3.setFont(new Font(MainFrame.fontType, Font.PLAIN, 20));
//		然后再出初化，并加入监听事件中：
		menuItem1.addActionListener(this);
		menuItem2.addActionListener(this);
		menuItem3.addActionListener(this);
		
		popupMenu1.add(menuItem1);
		popupMenu1.add(menuItem2);
		popupMenu1.add(menuItem3);
		//在this中加入popupMenu1
		getContentPane().add(popupMenu1);
		
//#########TODO 表格实例化（Customer）
		//表格标题行
		String[] columnNames = {"文件名称","修改时间","文件类型","文件大小","文件路径"};
		tableModel = new MyTableModel<FileInfo>(columnNames, FileInfo.class);//实例化模板
		table = new JTable(tableModel);//创建表格面板
		table.setPreferredScrollableViewportSize(new Dimension(screenSize.width*2/3-60,screenSize.height/3));
		//视图高度填充
		table.setFillsViewportHeight(true);
		table.setAutoCreateRowSorter(true);
		table.setRowHeight(33);//设置行高
		//设置表头字体样式
		table.getTableHeader().setFont( new Font(MainFrame.fontType, Font.BOLD, 20) );
		table.getTableHeader().setBackground(new Color(250,217,127));
		//设置表内字体样式
		table.setFont(new Font(MainFrame.fontType, Font.PLAIN, 18));
		//单击事件定义
		table.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(e.getButton()==MouseEvent.BUTTON3) {//右键事件
					popupMenu1.show(table,e.getX(), e.getY());
				}else if (e.getButton()==MouseEvent.BUTTON1 && e.getClickCount()==2) {//双击事件
					//调用系统默认程序打开文件
					try {
						Runtime.getRuntime().exec("rundll32 url.dll FileProtocolHandler " + table.getValueAt(table.getSelectedRow(), 4));
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
						JOptionPane.showMessageDialog(null, "文件打开失败！可能是不允许的格式文件！");
					}
				}
			}
		});
		//将表格放入滚动面板中
		JScrollPane scrollPane = new JScrollPane(table);
		getContentPane().add(scrollPane, BorderLayout.CENTER);
		//初始化表格：
		initTable(MainFrame.ROOT_PATH,pageIndex);//默认选中图片文件夹
		System.out.println("表格初始化完成");
		
//######TODO 开线程 ：实时更新选中的行数 
		new Thread(new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				while(true) {
					try {
						Thread.sleep(200);
						//每0.2秒更新一次
						selectdCount = table.getSelectedRowCount();
						
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}).start();
		
//#######TODO  线程2： 深色模式的实现
		new Thread(new Runnable() {
			@Override
			public void run() {
				while(true) {
					darkMode();
					try {
						Thread.sleep(200);//间隔0.2秒刷新一次
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}).start();
	}
	
	/**
	 * 表格初始化
	 * @param path
	 */
	public void initTable(String path,int type) {
		List<List<FileInfo>> files = FileController.getFilesByType(new File(path));
		//如果有内容则更新表格
		if(files!=null && files.size()>0) {//查询到有文件
			//先设置好各类文件的数量
			audioCount.setText(String.valueOf(files.get(0).size()));
			videoCount.setText(String.valueOf(files.get(1).size()));
			imageCount.setText(String.valueOf(files.get(2).size()));
			docCount.setText(String.valueOf(files.get(3).size()));
			otherCount.setText(String.valueOf(files.get(4).size()));
			switch (type) {
			case 0:
				updateTable(files.get(0));
				break;
			case 1:
				updateTable(files.get(1));			
				break;
			case 2:
				updateTable(files.get(2));
				break;
			case 3:
				updateTable(files.get(3));
				break;
			case 4:
				updateTable(files.get(4));
				break;

			default:
				break;
			}
		}
	}

	/**
	 * 更新表格
	 * @param fs
	 */
	public void updateTable(List<FileInfo> fs) {
		if(fs!=null && fs.size()>0) {//有文件
			Vector<FileInfo> list = new Vector<FileInfo>();
			for (FileInfo f : fs) {
				if(f.getType().equals("文件夹")) {//文件夹不用加大小
					f.setSize("");
				}
				list.add(f);
			}
			//更新数据
			tableModel.updateData(list);
			table.setRowSelectionInterval(0, 0);//默认选中第一行
		}else {
			table.removeAll();//清空
		}
	}
	/**
	 * 右键菜单的点击事件处理
	 */
	@Override
	public void actionPerformed(ActionEvent e1) {
		// TODO Auto-generated method stub
		String command = e1.getActionCommand();//获取点击事件源
		switch (command) {
			case "打开":
				if(selectdCount>0) {
					int[] selectedRows = table.getSelectedRows();
						try {//调用系统进程打开文件
							Runtime.getRuntime().exec("rundll32 url.dll FileProtocolHandler " + table.getValueAt(selectedRows[0], 4));
						} catch (IOException e) {
							e.printStackTrace();
							JOptionPane.showMessageDialog(null, "文件打开失败！可能是格式不合法的文件！");
						}
				}else {
					JOptionPane.showMessageDialog(null, "请先选择要打开的文件！");
				}
				break;
			case "删除":
				if(selectdCount==0) {//没有选中
					JOptionPane.showMessageDialog(null, "请先选中要删除的内容！");
				}else {
					//获取选中的行
					int[] selectedRows = table.getSelectedRows();
					int toDel = JOptionPane.showConfirmDialog(null, "确定要删除  "+table.getValueAt(selectedRows[0], 0)+"...等"+selectdCount+"个文件吗？","温馨提示",JOptionPane.YES_NO_OPTION);
					if(toDel==0) {//确认删除
						boolean deleted = false;
						for (int i : selectedRows) {
							String delPath = (String) tableModel.getValueAt(i, 4);//选中path列，删除文件依据的是文件URI
							deleted = FileController.deleteFile(delPath);
						}
						if(deleted) {//删除成功
							JOptionPane.showMessageDialog(null, "删除成功！");
							initTable(MainFrame.ROOT_PATH, pageIndex);
						}else {
							JOptionPane.showMessageDialog(null, "删除出错！");
						}
					}
				}
				break;
			case "重命名":
				if(selectdCount>1) {//选中多行
					JOptionPane.showMessageDialog(null, "一次只能重命名一个文件哦");
				}else {
					String rePath = (String)table.getValueAt(table.getSelectedRow(), 4);//原文件路径
					String newName = JOptionPane.showInputDialog("请输入新的文件名（不用加后缀名）：\n注意：输入空内容相当于取消重名名\n");
					if(newName!=null && newName.trim().length()>0) {
						if(!table.getValueAt(table.getSelectedRow(), 2).equals("文件夹")) {//如果是文件，则补上后缀名
							newName += rePath.substring(rePath.lastIndexOf("."),rePath.length());
						}
						boolean r = FileController.reName(rePath, newName);
						if(r) {
							JOptionPane.showMessageDialog(null, "文件重命名成功！");
							initTable(MainFrame.ROOT_PATH.trim(),pageIndex);
						}else {
							JOptionPane.showMessageDialog(null, "同一目录下已含有同名文件，重名名失败！");
						}
					}
				}
				break;
		}
		
	}
	
	/**
	 * 设置字体样式
	 * @param component
	 */
	public static void setFontStyle(JComponent component,int fontClass) {
		switch (fontClass) {
		case 1://一级菜单
			component.setFont(new Font(MainFrame.fontType, Font.BOLD, 30));
			break;
		case 2://二级菜单
			component.setFont(new Font(MainFrame.fontType, Font.BOLD, 20));
			break;
		default: 
			break;
		}
		component.setForeground(MainFrame.darkMode?new Color(255, 255, 255):new Color(0, 0, 0));//根据深色模式来调整字体颜色
	}
	
	//深色模式
	public static void darkMode() {
		//深色模式下的字体样式调整
		setFontStyle(audioCount,1);
		setFontStyle(videoCount, 1);
		setFontStyle(imageCount, 1);
		setFontStyle(docCount, 1);
		setFontStyle(otherCount, 1);
		setFontStyle(lblNewLabel, 1);
		setFontStyle(lblNewLabel_2, 1);
		setFontStyle(lblNewLabel_3, 1);
		setFontStyle(lblNewLabel_4, 1);
		setFontStyle(lblNewLabel_5, 1);
		table.setFont(new Font(MainFrame.fontType,Font.PLAIN,20));
		table.setForeground(MainFrame.darkMode?new Color(255, 255, 255):new Color(0, 0, 0));
		setFontStyle(table.getTableHeader(), 2);
		//深色模式下背景颜色调整
		table.setBackground(MainFrame.darkMode?MainFrame.bgColorAtDart:MainFrame.defaultBgColor);
		panel.setBackground(MainFrame.darkMode?MainFrame.bgColorAtDart:MainFrame.defaultBgColor);
		table.getTableHeader().setBackground(MainFrame.darkMode?new Color(227,196,116):new Color(250,217,127));
	}
}
